package alg.list;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author:yuziji
 * @create: 2023-04-24 16:47
 */
public class DeleteList {
    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);
        Node node = deleteNode(head, 3);
        node.printNode(node);
    }

    private static Node deleteNode(Node head,int val){
        if (head.value==val){
            return head.next;
        }
        Node prev = head;//引用头一个节点
        Node next = head.next;//引用后一个节点
        while(next!=null){
            if (next.value == val){
                prev.next = next.next;
            }else {
                prev = next;
            }
            next = next.next;
        }
        return head;
    }


}
